package com.xy.ocp.improve;


/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/7 20:51
 * @description opc原则优化
 */
public class Improve {
    public static void main(String[] args) {
        new GraphicEditor().draw(new Circle());
        new GraphicEditor().draw(new Rectangle());
        new GraphicEditor().draw(new Triangle());
    }
}


class GraphicEditor {
    public void draw(Shape shape) {
        shape.draw();
    }
}

abstract class Shape {
    int m_type;

    abstract void draw();

}

class Circle extends Shape {

    public Circle() {
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}


class Rectangle extends Shape {
    public Rectangle() {
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

class Triangle extends Shape {
    public Triangle() {
        super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}